
#ifndef __ECDSA_PUBLIC_KEY_H
#define __ECDSA_PUBLIC_KEY_H

#include <openssl/ecdsa.h>
#include "../iface/SSLInterface.h"
#include "PublicKey.h"
#include "CheckingKey.h"

/** An class encapsulating an ECDSA public key. */
class ECDSAPublicKey : public PublicKey, public CheckingKey
{
   public:
      ECDSAPublicKey();
      ECDSAPublicKey(const char *name);
      // Construct a duplicate of the public key
      ECDSAPublicKey(const ECDSAPublicKey &other);
      // Construct from PEM format
      ECDSAPublicKey(const char *pemtext, const char *name);
      // Construct from OpenSSL format
      ECDSAPublicKey(EC_KEY *pubkey, const char *name);
      // Copy assignment operator
      ECDSAPublicKey &operator=(const ECDSAPublicKey &other);
      // Destroy public key
      ~ECDSAPublicKey();
      // Get context
      int getCryptlibContext(CRYPT_CONTEXT *keycontext);
      // Get Checking context
      int getCryptlibCheckingContext(CRYPT_CONTEXT *keycontext);
      // Get key components
      int getCryptlibKeyComponents(CRYPT_PKCINFO_ECC *ecdsakey);
      // Get new OpenSSL ECDSA object
      int getSSLKeyComponents(EC_KEY **pubkey);
      // Get PEM data
      int getPEMKeyData(char **pemtext);
      // Get OpenSSH binary blob
      int getSSHKeyBlob(char **blob, int *reallength);
      // Get OpenSSH text with key label
      int getSSHKeyBlob(char **textblob, const char *keylabel);
      // Compare key to key
      int compareKeyEqual(PublicKey *pubkey);
      // Get key type name
      int getKeyType() { return KEY_TYPE_PUBLIC_ECDSA; }
      // To import from text - Base64 RAW or PEM
      int importKeyFromASCII(const char *text, const char *name);
      // To export to text - Base64 RAW or PEM
      int exportKeyToASCII(char **text);
      // Import from text with password
      int importKeyFromASCIIWithPassword(const char *text, const char *password, const char *name);
      // Export to text with password
      int exportKeyToASCIIWithPassword(char **text, const char *password);
   private:
      static int copyECDSASSLPublicKey(EC_KEY *dst, EC_KEY *src);
      /** A pointer to the real ECDSA public key, held in SSL format. */
      EC_KEY *key;
      /** A pointer to the curve group type. */
      EC_GROUP *group;
};

#endif
